package com.lxq.test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 龙小虬
 * @date 2021/4/23 9:16
 */
public class MyLock implements Runnable {
    private static int count = 0;
    //    private static Lock lock = new ReentrantLock(true);
    private static Lock lock = new ReentrantLock(false);

    @Override
    public void run() {

        while (count < 200) {
            createCount();
        }
    }

    public synchronized void createCount() {
        System.out.println(Thread.currentThread().getName() + ",count:" + count);
        count++;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(new MyLock()).start();
        }
    }
}
